//显示消息提示层
function showNotice(msg){
	boxview(msg);
	$('.boxview_ok').remove();
}
//通用浮动层
function boxview(msg){
	var str = '<div class="boxview"><h3>温馨提示</h3><div class="boxview-main">'+msg+'</div>';
	str     = str + '<div class="boxview_button"><img src="themes/1d1c/images/dc_cart_ok.jpg" class="boxview_ok"><img src="themes/1d1c/images/dc_cart_del.jpg" class="boxview_del" onclick="return boxviewClose();"></div>';
	str     = str + '</div>';
	$('body').append(str);
	$('.boxview').css('left',(parseInt(document.body.offsetWidth) - $('.boxview').width()) / 2 + "px");// 屏幕居中
	$('.boxview').css('top',parseInt(window.screen.height)-parseInt($('.boxview').height())/2 + "px");
}
function boxviewClose(){
	$('.boxview').remove();
}
$(function(){
	$('#menu ul li').last().addClass('cur');
	//设置活动目录
	var index = $('.smenu li').find('.onclass').parents('li').index();
	if(parseInt(index)>0){
		$('#menu ul li').attr('rel','');
		$('.smenu').show();
		$('.smenu ul li:eq('+index+')').show();
		$('#menu ul li:eq('+index+')').find('a').attr('class','cur');
		$('#menu ul li:eq('+index+')').attr('rel','act');
	}
	$('.dc_change_address').click(function(){
		$('#formAddress').show();
	})
	//浮动菜单显示
	var index = '';
	$('#menu li,.smenu li').hover(
		  function(){
	   			$('.smenu').show();
				index = $(this).index();
				$('.smenu li').hide();
				$('.smenu li:eq('+index+')').show();
		  },
		  function(){			
				var act = $('#menu li[rel=act]').index();
				if(act != index){
					//显示原来的
					$('.smenu li').hide();
					$('.smenu li:eq('+act+')').show();
		  }
	})
	//登陆处理
	$('.dc_box_login .bnt_dc_login').live('click',function(){
		var obj = $(this).parents('form');
		var username = obj.find('input[name=username]').val();
		var userdate =  obj.find('input[name=username]').attr('date');
		if((username.length<1) || (username == userdate)){
			alert('请输入'+userdate);
			return false;
		}
	})

	//检测是否登陆
	$('.checklogin').click(function(){
		var status = ajaxUserCheck('action=user.checklogin');
		if(status == "0")
			return true;
		if(status == '1'){
			jQuery.WboxAction.showLoginBox();
			$('input[name="before_url"]').val(window.location.href);
		}
		else
			alert(status);
		return false;
	})

	$('.dc_change_address').click(function(){
		$('.rao_shrinfo').hide();
		$('.rao_shrchange').show();
	})
	//删除配送地址
	$('.rao_flow_del').click(function(){
		alert("禁用51");
		var address_id = $(this).attr('rel');
		var html = $.ajax({
			  url:''+address_id+"&"+Math.random(),
			  async: false
			 }).responseText;
		$(this).parents('.cart_add').remove();
	})
	//修改配送地址
	$('.rao_paymethod_change').click(function(){
		var display = $(this).parents('.cart_add').find('.cart_flow_change').css('display');
		$('.cart_flow_change').hide();
		if(display == 'none'){
			$(this).parents('.cart_add').find('.cart_flow_change').show();
		}else{
			$(this).parents('.cart_add').find('.cart_flow_change').hide();
		}
		var address_id=$(this).attr('value');
		$("#bdate_"+address_id).blur();
	})
	//订单提交前处理
	$('.rao_cart_done').click(function(){
			var dely_date = $("#dely_date").val();
			var dely_time = $("#dely_time").val();
			if(dely_date == "" || dely_time == "")
			{
				alert("请选择送/取货日期和时间段");
				return false;
			}
		//获取配送方式
		var shiping = $('input[name=shipping]:checked').val();
		if(shiping == 4){//送货上门,判断送货时间
			if($('input[name=check_paymethod]').val() != 1){//检查配送标记
				//自动处理配送时间
				var date = '';
				var obj = $('.rao_paymethod_change:checked').parents('.cart_add');
				var address_id = obj.find('input[name=address_id]').val();
				date = date+'&address_id='+address_id;
				if(address_id == ''){
					date = date+'&country='+obj.find('select[name=country]').val();
					date = date+'&province='+obj.find('select[name=province]').val();
					date = date+'&city='+obj.find('select[name=city]').val();
					date = date+'&consignee='+encodeURI(obj.find('input[name=consignee]').val());
					date = date+'&address='+encodeURI(obj.find('input[name=address]').val());
				}else{
					date = date+'&country='+obj.find('input[name=country]').val();
					date = date+'&province='+obj.find('input[name=province]').val();
					date = date+'&city='+obj.find('input[name=city]').val();
					date = date+'&consignee='+obj.find('input[name=consignee]').val();
					date = date+'&address='+obj.find('input[name=address]').val();
				}
				date = date+'&best_time='+obj.find('input[name=best_time]').val();
				date = date+'&bdate='+obj.find('input[name=bdate]').val();
				date = date+'&district='+obj.find('input[name=district]').val();
				date = date+'&email='+obj.find('input[name=email]').val();
				date = date+'&zipcode='+obj.find('input[name=zipcode]').val();
				date = date+'&tel='+obj.find('input[name=tel]').val();
				date = date+'&mobile='+obj.find('input[name=mobile]').val();
				date = date+'&sign_building='+obj.find('input[name=sign_building]').val();
				//提交前先判断数据是否都填写
				if(address_id == ''){//其他地址
					if(obj.find('select[name=city]').val() == 0){
						alert('请选择配送区域');
						return false;
					}
					var address  = obj.find('input[name=address]').val();
					if(address.length < 1){
						alert('请输入详细配送地址 ');
						return false;
					}
					var consignee  = obj.find('input[name=consignee]').val();
					if(consignee.length < 1){
						alert('请输入收货人姓名 ');
						return false;
					}
					var tel  = obj.find('input[name=tel]').val();
					if(tel.length < 1){
						alert('请输入收货人手机 ');
						return false;
					}
					var mobile  = obj.find('input[name=mobile]').val();
					if(mobile.length < 1){
						alert('请输入您的手机 ');
						return false;
					}
				}
			}
		}else if(shiping == 9){//用户自提
			var rao_consignee = $('input[name=rao_consignee]').val();
			if(rao_consignee.length < 1){
				alert('请输入取货人姓名 ');
				return false;
			}
			var rao_tel = $('input[name=rao_tel]').val();
			if(rao_tel.length < 1){
				alert('请输入取货人手机 ');
				return false;
			}
			var rao_mobile = $('input[name=rao_mobile]').val();
			if(rao_mobile.length < 1){
				alert('请输入您的手机 ');
				return false;
			}			
		}
		var obj        = document.getElementById('ECS_NEEDINV');
		var objPayee   = document.getElementById('ECS_INVPAYEE');
		var needInv    = obj.checked ? 1 : 0;
		var invPayee   = obj.checked ? objPayee.value : '';
		
		if(needInv==1)
		{
			if(invPayee=='请填写公司名称或者个人真实姓名' || invPayee=='')
			{
				alert('发票抬头请填写公司名称或者个人真实姓名');
				return false;
			}
		}
		
	})
})

function ajaxUserCheck(url){
	var html = $.ajax({
		  url:'index.php?'+url+"&"+Math.random(),
		  async: false
		 }).responseText;
	return html;
}

function hidePassword(obj)
{
		var user_password=$("#f_password").attr('value');
		
		if($(obj).hasClass('cur'))
		{
			$(obj).removeClass('cur');

			var obj='<input type="text" class="inputBg1" name="password" id="f_password" onblur="f_check_password(this.value);" onkeyup="checkIntensity(this.value)" value="'+user_password+'">';
							
			$("#password_box2").empty().append(obj);
		}
		else{
			$(obj).addClass('cur');
							
			var obj='<input type="password" class="inputBg1" name="password" id="f_password" onblur="f_check_password(this.value);" onkeyup="checkIntensity(this.value)" value="'+user_password+'">';
			
			$("#password_box2").empty().append(obj);							
		}		
}

$(document).ready(function(){
		/*测试代码，上线之前去除*/
		var html_str = $(document.documentElement).html();
		if(html_str.indexOf('Notice') != -1)
			alert("页面有错误(Notice)，请查看源码");
		/*end*/
});
